package com.coffee.tenant;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

/**
 * @author songkui
 * @since 2024-4-17 1:18
 */
@Aspect
@Slf4j
public class CoffeeIgnoreTenantAspect {

    @Pointcut("@annotation(com.coffee.tenant.CoffeeIgnoreTenant)")
    public void pointcut() {
    }

    @Around(value = "pointcut()")
    public Object operationLogController(ProceedingJoinPoint point) throws Throwable {

        String clsName = point.getTarget().getClass().getSimpleName();
        String methodName = point.getSignature().getName();
        log.info("Coffee ignore tenant [{} : {}]", clsName, methodName);
        try {
            TenantContextHolder.setIgnore(true);
            return point.proceed();
        } finally {
            TenantContextHolder.clear();
        }
    }


}
